package com.cqut.ktpspring.controller;
import com.cqut.ktpspring.pojo.Result;
import com.cqut.ktpspring.pojo.User;
import com.cqut.ktpspring.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@Slf4j
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/findByUid")
    public Result findByUid(@RequestParam String id) {
        log.info("根据id查询信息:{}",id);
        User user=userService.findByUid(id);
        return Result.success(user);
    }

    @PutMapping("/updateUser")
    public Result updateUser(@RequestBody User user) {
        log.info("更新用户信息:{}",user);
        userService.update(user);
        return Result.success();
    }

    @GetMapping("/getAllUser")
    public Result getAllUser() {
        log.info("获得所有数据");
        List<User> userList=userService.getAll();
        return Result.success(userList);
    }

}
